<template>
  <div class="dashboard">
    <!-- 1.顶部数字的数据展示 -->
    <el-row :gutter="10">
      <template v-for="item in dashboardStore.amountList" :key="item.amount">
        <el-col :span="6" :xs="24" :sm="12" :md="8" :lg="6">
          <count-card v-bind="item" />
        </el-col>
      </template>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="7">
        <MieCard title="分类仓库数量(饼图)">
          <PieEchart :pieData="pieData"></PieEchart>
        </MieCard>
      </el-col>
      <el-col :span="10">
        <MieCard title="不同仓库货物销量">
          <MapEchart :mapData="mapData"></MapEchart>
        </MieCard>
      </el-col>
      <el-col :span="7">
        <MieCard title="分类仓库数量(玫瑰图)">
          <RoseEchart :roseData="pieData"></RoseEchart>
        </MieCard>
      </el-col>
    </el-row>

    <el-row :gutter="20">
      <el-col :span="12">
        <MieCard title="分类仓库的销量">
          <LineEchart v-bind="lineData"></LineEchart>
        </MieCard>
      </el-col>
      <el-col :span="12">
        <MieCard title="分类仓库的收藏">
          <BarEchart v-bind="barData"></BarEchart>
        </MieCard>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import useDashboard from "@/stores/main/analysis/dashboard";
import CountCard from "./cpns/count-card/count-card.vue";
import MieCard from "@/base-ui/card";
import {
  PieEchart,
  RoseEchart,
  LineEchart,
  BarEchart,
  MapEchart,
} from "@/components/page-echarts";

const dashboardStore = useDashboard();
dashboardStore.initDashboardDataAciton();

const pieData = computed(() => {
  const categoryCount = dashboardStore.categoryCount;
  const transformCategoryCount = categoryCount.map((item: any) => {
    return {
      name: item.name,
      value: item.goodsCount,
    };
  });
  return transformCategoryCount;
});

const mapData = computed(() => {
  return dashboardStore.addressSale.map((item: any) => {
    return { name: item.address, value: item.count };
  });
});

const lineData = computed(() => {
  const xLabels = [];
  const values = [];
  const categorySale = dashboardStore.categorySale as any;
  for (const item of categorySale) {
    xLabels.push(item.name);
    values.push(item.goodsSale);
  }
  return { xLabels, values };
});

const barData = computed(() => {
  const xLabels = [];
  const values = [];
  const categoryFavor = dashboardStore.categoryFavor as any;
  for (const item of categoryFavor) {
    xLabels.push(item.name);
    values.push(item.goodsFavor);
  }
  return { xLabels, values };
});
</script>

<style lang="less" scoped>
.el-row {
  margin-bottom: 20px;
}
</style>
